package com.hightrast.service.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.hightrast.service.api.baseEntity.R;
import com.hightrast.service.api.domain.qo.rastUser.LoginQo;
import com.hightrast.service.api.domain.qo.rastUser.RegisterQo;
import com.hightrast.service.api.domain.qo.rastUser.UpdateForgotPasswordQo;
import com.hightrast.service.api.domain.vo.rastUser.LoginVo;
import com.hightrast.service.service.impl.RastUnAuthOpenServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 不校验token 用户登陆、注册、修改密码 前端控制器
 * </p>
 *
 * @author hx
 * @since 2025-01-11
 */
@RestController
@RequestMapping("/api/un-auth-open")
@Api(tags = "用户登陆、注册、修改密码 前端控制器")
public class RastUnAuthOpenController {

    @Resource
    RastUnAuthOpenServiceImpl unAuthOpenService;

    @ApiOperation("登陆")
    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody @Valid LoginQo qo) {
        return R.data(unAuthOpenService.login(qo));
    }

    @ApiOperation("注册")
    @PostMapping("/register")
    public R<Void> register(@RequestBody @Validated RegisterQo qo) {
        unAuthOpenService.register(qo);
        return R.success();
    }

    @ApiOperation("重置密码")
    @PostMapping("/forgotPassword")
    public R<Void> forgotPassword(@RequestBody @Validated UpdateForgotPasswordQo qo) {
        unAuthOpenService.forgotPassword(qo);
        return R.success();
    }

    @ApiOperation("注销登陆")
    @GetMapping("/logout")
    public R<Void> logout() {
        StpUtil.logout();
        return R.success();
    }

}
